﻿<UserControl x:Class="ScrumFactory.Login.LoginDialog"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:props="clr-namespace:ScrumFactory.Login.Properties"        
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
        
            x:Name="thisView"
           
            SnapsToDevicePixels="True"
        
            Width="630">
    <UserControl.InputBindings>
        <KeyBinding Key="Enter" Command="{Binding SignInCommand}"/>
    </UserControl.InputBindings>
    <UserControl.Resources>        
        <DataTemplate x:Key="ProviderTemplate">                       
                <TextBlock 
                    FontWeight="DemiBold"
                    Text="{Binding ProviderName, StringFormat={x:Static props:Resources.authenticate_at_P}}" Style="{StaticResource LabelTextBlock}" VerticalAlignment="Center"/>         
        </DataTemplate>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>                     
        </Grid.RowDefinitions>


        <Border Grid.ColumnSpan="2" Grid.Row="0" HorizontalAlignment="Stretch" Margin="3" BorderThickness="2" >
            <Border.Style>
                <Style TargetType="{x:Type Border}" BasedOn="{StaticResource AlertBorder}">                    
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding LoginStatusMessage}" Value="{x:Null}">
                            <Setter Property="Border.Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
            <TextBlock TextWrapping="Wrap" Text="{Binding LoginStatusMessage}"/>
        </Border>

        <Grid Grid.ColumnSpan="2" Grid.Row="1" HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>

            <ComboBox                                                       
                MinWidth="150" Grid.Column="0" HorizontalAlignment="Left"  VerticalAlignment="Center"
                BorderBrush="Transparent"                 
                SelectedItem="{Binding SelectedProvider}" 
                ItemTemplate="{StaticResource ProviderTemplate}"
                ItemsSource="{Binding AllProviders}" />

            <TextBlock FontSize="{StaticResource SmallFontSize}" Text="at" Style="{StaticResource LabelTextBlock}" Grid.Column="1" VerticalAlignment="Center"/>
            <TextBox 
                MaxWidth="350" Grid.Column="2"  VerticalAlignment="Center"
                FontSize="{StaticResource SmallFontSize}"                
                Style="{StaticResource HyperLinkTextBox}"
                Text="{Binding ServerUrl}"/>
        </Grid>
        


        <TextBlock             
            Grid.Column="0" Grid.Row="2" Text="{x:Static props:Resources.User_email}" Style="{StaticResource LabelTextBlock}" />
        <TextBox Grid.Column="1" Grid.Row="2"  Text="{Binding User}"  HorizontalAlignment="Stretch" IsReadOnly="{Binding IsUserFieldReadOnly}" Padding="30,4,2,4" />
        <Image Grid.Column="1" Grid.Row="2" Margin="11,1,0,0" Source="{Binding SelectedProvider.ProviderImageUrl}" Width="24" Height="24" HorizontalAlignment="Left"/>


        <TextBlock Grid.Column="0" Grid.Row="3" Text="{x:Static props:Resources.Password}" >
            <TextBlock.Style>
                <Style BasedOn="{StaticResource LabelTextBlock}" TargetType="{x:Type TextBlock}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsUserFieldReadOnly}" Value="True">
                            <Setter Property="Visibility" Value="Hidden"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
        <PasswordBox Grid.Column="1" Grid.Row="3" Name="passwordTextBox"  HorizontalAlignment="Stretch" PasswordBox.PasswordChanged="PasswordBox_PasswordChanged">
            <PasswordBox.Style>
                <Style TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource {x:Type PasswordBox}}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding PasswordRequired}" Value="False">
                            <Setter Property="Visibility" Value="Hidden"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </PasswordBox.Style>
        </PasswordBox>

        <CheckBox Grid.Column="1" Grid.Row="4" HorizontalAlignment="Right"
                  IsChecked="{Binding RemindUser}"
                  Content="{x:Static props:Resources.remind_me}"/>

        <Border
                HorizontalAlignment="Stretch"
                Background="{StaticResource WindowButtonBar}"
                Grid.ColumnSpan="2" Grid.Row="5">

            <Button
                    MinWidth="80" Margin="5" HorizontalAlignment="Center"
                    Command="{Binding SignInCommand}" Content="{x:Static props:Resources.Sign_in}"/>
        </Border>


    </Grid>
</UserControl>
